$SPath=$PATH_INFO;
$CookieDeath=20;
@$Conn=mysql_connect("adresa_srv","user_id","heslo");
mysql_select_db("moje_database");
if (empty($CounterID)){
	$SQLText="SELECT * FROM Tcounter WHERE SPath='$SPath'";
	$result=mysql_query($SQLText);
	if (mysql_num_rows($result)==0){
		$SQLText="INSERT INTO Tcounter (SPath,Visits) VALUES ('$SPath',1)";
		$result=mysql_query($SQLText);
		$Visits=1;
		$CounterID=mysql_insert_id($result);
	}
	else{
		$row=mysql_fetch_array($result);
		$Visits=++$row["Visits"];
		$CounterID=$row["CounterID"];
		$SQLText="UPDATE Tcounter SET Visits=$Visits WHERE CounterID=$CounterID";
		$result=mysql_query($SQLText);
	}
}
else{
	$SQLText="SELECT Visits FROM Tcounter WHERE CounterID=$CounterID";
	$result=mysql_query($SQLText);
	$row=mysql_fetch_array($result);
	$Visits=$row["Visits"];
}
mysql_close($Conn);
setcookie("CounterID",$CounterID,(time()+$CookieDeath*60));
CREATE TABLE Tcounter(
CounterID INT NOT NULL PRIMARY KEY AUTO_INCREMENT, -- identifikator počítadla
SPath VARCHAR(122), -- cesta ke stránce kterou monitorujeme
Visits INT -- počet návštěv
);  
?>